import React, {Component} from "react";
import InputBox from "../../common/InputBox.js";
import Confirm from "../../common/Confirm.js";
import Relay from "react-relay";
import ReplyTicklingMutation from './mutation/ReplyTicklingMutation';


import {_Modal,_Icon} from 'ANT_DE';
const Modal = _Modal,
       Icon = _Icon;

export default class Addstaff extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            visible: false,
            title: "",
            uid: "",
        };
        this.style = {
            confirm: {
                width: '60px',
                height: '30px',
                backgroundColor: "#1b3249",
                fontSize: "18px",
                color: "#fff",
                marginTop: "16px",
                marginLeft: "20px",
                fontFamily: "Microsoft YaHei"
            }
        }
    }
    /*初始化数据显示*/
    initHit() {
        this.isRelay = true;
        this.setState({
            visible:this.state.visible
        });
    }

    bluron(type) {
        switch (type) {
            case 'detail':
                var content = this.refs.content.state.text;
                if (content == "") {
                    this.isRelay = false;
                    this.setState({
                        companyhint: "姓名不能为空"
                    });
                } else {
                    this.setState({
                        companyhint: ""
                    });
                }
                return;

        }
    }

    /*点击确认*/
    handleConfirm(flag) {
        var id=this.state.uid;
        var content=this.refs.content.state.text.trim();
        var label=1;
        if(content === null || content === undefined || content === ''){
            this.refs.contentPoint.textContent="回复内容不允许为空"
            return;
        }else{
            this.refs.contentPoint.textContent=""

        }
    // debugger;
        Relay.Store.commitUpdate(
            new  ReplyTicklingMutation({
                suggestId: id,
                label: label,
                detail: content
            }),
            {
                onFailure: () => {
                },
                onSuccess: (response) => {
                    var data = response.saveReply.saveReply;
                    if (data.errorCode == 0) {
                        this.showInfo("", "回复成功");
                        this.setState({
                            visible: false
                        });
                        this.props.getTicklingList(1,10);
                    } else {
                        this.showError("error",data.value);
                    }
                }
            }
        )
    }

    handleCancel = (e) => {
        this.setState({
            visible: false,
        });
    }

    /**错误提示框*/
    showError(title, value) {
        Modal.error({
            title: !title ? "提示：" : title,
            content: value,
            width: 390
        });
    }

    /*成功提醒*/
    showInfo(title, value) {
        Modal.info({
            title: !title ? "提示：" : title,
            content: value,
            width: 390
        });
    }
    //asdasd
    render() {
        return (
            <Modal className="modal_gre-title"
                   visible={this.state.visible}
                   style={{width: "634px", height: "765px"}}
                   onCancel={this.handleCancel}
                   title={this.state.title} key={this.key}
                   onOk={this.handleConfirm.bind(this)}
            >
                {/*<span style={{position: "absolute", display: "block", left: 360, top: 17}}>意见回复</span>*/}
                <span style={{marginLeft:109,color:'#EF112B'}} ref={'contentPoint'}></span>
                <div>
                    <div className="ticking_modal-content">
                        <span className="_left"> 意见回复： </span>
                        <div>
                            <InputBox  className="addstaff_input_bro_no" defaultvalute="请输入回复内容" space="40px"
                                       style={{width: 312, height: 150, borderColor: "#efefef", color: "#999", paddingRight: 57,paddingLeft:10,paddingTop:5}}
                                       ref={'content'} multiline={true} maxlength={200} bluron={this.bluron.bind(this, 'detail')}/>
                        </div>

                    </div>
                </div>

            </Modal>
        )
    }
}


